<!-- pages/partner/detail.vue -->
<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="nav-back" @tap="navigateBack">
        <text class="back-icon">←</text>
      </view>
      <text class="nav-title">搭子详情</text>
      <view class="nav-placeholder"></view>
    </view>

    <!-- 搭子基本信息 -->
    <view class="partner-card card-shadow">
      <view class="partner-header">
        <view class="avatar-large">
          <text class="avatar-emoji">{{partnerInfo.avatar}}</text>
        </view>
        <view class="partner-main-info">
          <view class="partner-name">{{partnerInfo.name}}</view>
          <view class="partner-badge" v-if="partnerInfo.online">
            <text class="badge-dot"></text>
            <text class="badge-text">在线</text>
          </view>
        </view>
      </view>
      
      <view class="partner-stats">
        <view class="stat-item">
          <text class="stat-value">{{partnerInfo.studyDays}}</text>
          <text class="stat-label">一起学习天数</text>
        </view>
        <view class="stat-divider"></view>
        <view class="stat-item">
          <text class="stat-value">{{partnerInfo.messageCount}}</text>
          <text class="stat-label">消息数</text>
        </view>
        <view class="stat-divider"></view>
        <view class="stat-item">
          <text class="stat-value">{{partnerInfo.studyTime}}h</text>
          <text class="stat-label">学习时长</text>
        </view>
      </view>
      
      <view class="partner-actions">
        <button class="action-btn message-btn" @tap="navigateToChat">
          <text class="action-icon">💬</text>
          <text>发消息</text>
        </button>
        <button class="action-btn">
          <text class="action-icon">📊</text>
          <text>学习分析</text>
        </button>
      </view>
    </view>

    <!-- 搭子详细信息 -->
    <view class="info-section card-shadow">
      <view class="section-title">基本信息</view>
      
      <view class="info-item">
        <text class="info-label">考研方向</text>
        <text class="info-value">{{partnerInfo.major}}</text>
      </view>
      
      <view class="info-item">
        <text class="info-label">目标院校</text>
        <text class="info-value">{{partnerInfo.targetSchool}}</text>
      </view>
      
      <view class="info-item">
        <text class="info-label">目标分数</text>
        <text class="info-value">{{partnerInfo.targetScore}}</text>
      </view>
      
      <view class="info-item">
        <text class="info-label">搭子关系</text>
        <text class="info-value">{{partnerInfo.partnerSince}}</text>
      </view>
    </view>

    <!-- 学习进度对比 -->
    <view class="progress-section card-shadow">
      <view class="section-title">学习进度对比</view>
      
      <view class="progress-subject" v-for="(subject, index) in learningProgress" :key="index">
        <view class="subject-header">
          <text class="subject-name">{{subject.name}}</text>
          <text class="subject-score">{{subject.myProgress}}% / {{subject.partnerProgress}}%</text>
        </view>
        
        <view class="progress-bars">
          <view class="progress-label">我</view>
          <view class="progress-bar my-progress">
            <view class="progress-fill" :style="{width: subject.myProgress + '%'}"></view>
          </view>
          
          <view class="progress-label">搭子</view>
          <view class="progress-bar partner-progress">
            <view class="progress-fill" :style="{width: subject.partnerProgress + '%'}"></view>
          </view>
        </view>
      </view>
    </view>

    <!-- 共同目标 -->
    <view class="goals-section card-shadow">
      <view class="section-title">共同目标</view>
      
      <view class="goal-item" v-for="(goal, index) in goals" :key="index">
        <view class="goal-content">
          <text class="goal-icon">🎯</text>
          <view class="goal-info">
            <text class="goal-title">{{goal.title}}</text>
            <text class="goal-deadline">截止日期：{{goal.deadline}}</text>
          </view>
        </view>
        
        <view class="goal-status" :class="goal.completed ? 'completed' : ''">
          {{goal.completed ? '已完成' : '进行中'}}
        </view>
      </view>
      
      <button class="add-goal-btn">
        <text class="add-icon">+</text>
        <text>添加新目标</text>
      </button>
    </view>

    <!-- 解绑搭子 -->
    <view class="unbind-section">
      <button class="unbind-btn" @tap="confirmUnbind">解除搭子关系</button>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'

// 模拟获取路由参数
const partnerId = 5 // 实际应从路由获取: uni.getQueryString('id')

// 模拟搭子详细信息
const partnerInfo = ref({
  id: partnerId,
  name: '刘七',
  avatar: '👩‍🎓',
  major: '数学',
  targetSchool: '中国科学技术大学',
  targetScore: '380+',
  online: true,
  partnerSince: '2023-11-05 (2个月)',
  studyDays: 65,
  messageCount: 328,
  studyTime: 213
})

// 模拟学习进度数据
const learningProgress = ref([
  {
    name: '数学',
    myProgress: 65,
    partnerProgress: 70
  },
  {
    name: '英语',
    myProgress: 80,
    partnerProgress: 75
  },
  {
    name: '专业课',
    myProgress: 50,
    partnerProgress: 60
  },
  {
    name: '政治',
    myProgress: 40,
    partnerProgress: 35
  }
])

// 模拟共同目标数据
const goals = ref([
  {
    id: 1,
    title: '完成《高等数学》第三章习题',
    deadline: '2023-12-10',
    completed: true
  },
  {
    id: 2,
    title: '背完英语词汇3000个',
    deadline: '2023-12-15',
    completed: false
  },
  {
    id: 3,
    title: '完成10套政治模拟题',
    deadline: '2023-12-20',
    completed: false
  }
])

// 导航到聊天页面
const navigateToChat = () => {
  uni.navigateTo({
    url: `/pages/partner/chat?id=${partnerId}`
  })
}

// 返回上一页
const navigateBack = () => {
  uni.navigateBack()
}

// 确认解绑
const confirmUnbind = () => {
  uni.showModal({
    title: '解除搭子关系',
    content: `确定要解除与"${partnerInfo.value.name}"的搭子关系吗？解除后将无法恢复。`,
    confirmColor: '#ff4d4f',
    success: (res) => {
      if (res.confirm) {
        // 模拟API调用
        setTimeout(() => {
          uni.showToast({
            title: '已解除绑定',
            icon: 'success'
          })
          
          // 延迟返回
          setTimeout(() => {
            uni.navigateBack({
              delta: 1
            })
          }, 1000)
        }, 500)
      }
    }
  })
}
</script>

<style>
.container {
  min-height: 100vh;
  background-color: #f8f9fa;
  padding-bottom: 30rpx;
}

.nav-bar {
  height: 88rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #A8BF8F 0%, #8FA876 100%);
  padding: 0 30rpx;
}

.nav-back {
  width: 60rpx;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.back-icon {
  color: #fff;
  font-size: 36rpx;
  font-weight: bold;
}

.nav-title {
  color: #fff;
  font-size: 36rpx;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.nav-placeholder {
  width: 60rpx;
}

.card-shadow {
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  background: #fff;
  border-radius: 12rpx;
  margin: 20rpx;
  padding: 30rpx;
}

/* 搭子基本信息卡片 */
.partner-card {
  margin-top: 30rpx;
}

.partner-header {
  display: flex;
  align-items: center;
}

.avatar-large {
  width: 140rpx;
  height: 140rpx;
  border-radius: 50%;
  background: #f0f2f5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 30rpx;
  border: 4rpx solid #fff;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1);
}

.avatar-emoji {
  font-size: 70rpx;
}

.partner-main-info {
  flex: 1;
}

.partner-name {
  font-size: 40rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 12rpx;
}

.partner-badge {
  display: inline-flex;
  align-items: center;
  background: #f6ffed;
  padding: 4rpx 12rpx;
  border-radius: 20rpx;
}

.badge-dot {
  width: 12rpx;
  height: 12rpx;
  border-radius: 50%;
  background: #52c41a;
  margin-right: 8rpx;
}

.badge-text {
  font-size: 24rpx;
  color: #52c41a;
}

.partner-stats {
  display: flex;
  justify-content: space-around;
  margin: 40rpx 0;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
}

.stat-label {
  font-size: 24rpx;
  color: #999;
  margin-top: 8rpx;
}

.stat-divider {
  width: 2rpx;
  background: #eee;
}

.partner-actions {
  display: flex;
  justify-content: space-around;
  margin-top: 20rpx;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  border: none;
  border-radius: 30rpx;
  padding: 16rpx 30rpx;
  font-size: 28rpx;
  color: #666;
}

.message-btn {
  background: #e6f7ff;
  color: #1890ff;
}

.action-icon {
  margin-right: 8rpx;
  font-size: 32rpx;
}

/* 详细信息部分 */
.section-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 20rpx;
  padding-bottom: 16rpx;
  border-bottom: 2rpx solid #f5f5f5;
}

.info-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16rpx 0;
  border-bottom: 1px solid #f5f5f5;
}

.info-item:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 28rpx;
  color: #666;
}

.info-value {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
}

/* 学习进度对比部分 */
.progress-subject {
  margin-bottom: 30rpx;
}

.progress-subject:last-child {
  margin-bottom: 0;
}

.subject-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10rpx;
}

.subject-name {
  font-size: 28rpx;
  font-weight: 500;
  color: #333;
}

.subject-score {
  font-size: 24rpx;
  color: #666;
}

.progress-bars {
  display: flex;
  flex-direction: column;
  gap: 12rpx;
}

.progress-label {
  font-size: 24rpx;
  color: #999;
  width: 60rpx;
}

.progress-bar {
  height: 20rpx;
  background: #f5f5f5;
  border-radius: 10rpx;
  overflow: hidden;
  flex: 1;
  margin-bottom: 16rpx;
}

.progress-fill {
  height: 100%;
  border-radius: 10rpx;
}

.my-progress .progress-fill {
  background: linear-gradient(90deg, #8FA876 0%, #A8BF8F 100%);
}

.partner-progress .progress-fill {
  background: linear-gradient(90deg, #1890ff 0%, #69c0ff 100%);
}

/* 共同目标部分 */
.goal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1px solid #f5f5f5;
}

.goal-item:last-child {
  border-bottom: none;
}

.goal-content {
  display: flex;
  align-items: center;
  flex: 1;
}

.goal-icon {
  font-size: 36rpx;
  margin-right: 16rpx;
}

.goal-info {
  flex: 1;
}

.goal-title {
  font-size: 28rpx;
  color: #333;
  font-weight: 500;
  margin-bottom: 6rpx;
}

.goal-deadline {
  font-size: 24rpx;
  color: #999;
}

.goal-status {
  font-size: 24rpx;
  background: #fff7e6;
  color: #fa8c16;
  padding: 4rpx 12rpx;
  border-radius: 20rpx;
}

.goal-status.completed {
  background: #f6ffed;
  color: #52c41a;
}

.add-goal-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed #d9d9d9;
  background: none;
  padding: 14rpx 0;
  margin-top: 20rpx;
  border-radius: 8rpx;
  color: #8FA876;
  font-size: 28rpx;
}

.add-icon {
  font-size: 32rpx;
  margin-right: 8rpx;
}

/* 解绑按钮 */
.unbind-section {
  padding: 0 20rpx;
  margin-top: 40rpx;
}

.unbind-btn {
  width: 100%;
  background: none;
  border: 1px solid #ff4d4f;
  color: #ff4d4f;
  font-size: 28rpx;
  padding: 16rpx 0;
  border-radius: 8rpx;
}
</style>